package iterator.actors;

import iterator.extras.Book;
import iterator.roles.Aggregate;
import iterator.roles.Iterator;

/**
 * 类名：BookShelf
 * 类含义：表示书架实体，书架实体含有若干书本实体
 */
public class BookShelf implements Aggregate {
    private Book[] books;

    private int last = 0;

    public BookShelf(int maxsize) {
        this.books = new Book[maxsize];
    }

    public Book getBookAt(int index) {
        return books[index];
    }

    public void appendBook(Book book) {
        books[last] = book;
        last++;
    }

    public int getLength() {
        return last;
    }

    @Override
    public Iterator iterator() {
        return new BookShelfIterator(this);
    }
}
